package com.ruoyi.quartz.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.quartz.domain.DrugsNotice;
import com.ruoyi.quartz.service.IDrugsNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存预警Controller
 * 
 * @author wyj
 * @date 2025-04-25
 */
@RestController
@RequestMapping("/notice/notice")
public class DrugsNoticeController extends BaseController
{
    @Autowired
    private IDrugsNoticeService drugsNoticeService;

    /**
     * 查询库存预警列表
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugsNotice drugsNotice)
    {
        startPage();
        List<DrugsNotice> list = drugsNoticeService.selectDrugsNoticeList(drugsNotice);
        return getDataTable(list);
    }

    /**
     * 导出库存预警列表
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:export')")
    @Log(title = "库存预警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugsNotice drugsNotice)
    {
        List<DrugsNotice> list = drugsNoticeService.selectDrugsNoticeList(drugsNotice);
        ExcelUtil<DrugsNotice> util = new ExcelUtil<DrugsNotice>(DrugsNotice.class);
        util.exportExcel(response, list, "库存预警数据");
    }

    /**
     * 获取库存预警详细信息
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(drugsNoticeService.selectDrugsNoticeById(id));
    }

    /**
     * 新增库存预警
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:add')")
    @Log(title = "库存预警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugsNotice drugsNotice)
    {
        return toAjax(drugsNoticeService.insertDrugsNotice(drugsNotice));
    }

    /**
     * 修改库存预警
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:edit')")
    @Log(title = "库存预警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugsNotice drugsNotice)
    {
        return toAjax(drugsNoticeService.updateDrugsNotice(drugsNotice));
    }

    /**
     * 删除库存预警
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:remove')")
    @Log(title = "库存预警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(drugsNoticeService.deleteDrugsNoticeByIds(ids));
    }
}
